package com.xpgk.mvc.brefund;

import java.util.List;

import com.jfinal.log.Log;
import com.xpgk.annotation.Table;
import com.xpgk.mvc.base.BaseModel;
import com.xpgk.mvc.bentryRegister.CustomerProduct;
import com.xpgk.mvc.organization.Organization;



/**
 * 
 * 退款记录
 * 
 */

@SuppressWarnings("unused")
@Table(tableName = ProductReturn.table_name) 
public class ProductReturn extends  BaseModel<ProductReturn>{
	
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 7762869557938771747L;

	private static final Log log = Log.getLog(ProductReturn.class);

	public static final ProductReturn dao = new ProductReturn().dao();

	/**
	 * 字段描述：该条数据添加人员is  字段类型：character varying 长度：32
	 */
	public static final String column_createId = "createId";
	/**
	 * 字段描述：该条数据添加时间  字段类型：datetime 长度：0
	 */
	public static final String column_createDate = "createDate";
	/**
	 * 字段描述：该条数据更新人员id  字段类型：character varying 长度：100
	 */
	public static final String column_updateId = "updateId";
	/**
	 * 字段描述：该条数据更新时间  字段类型：datetime 长度：0
	 */
	public static final String column_updateDate = "updateDate";
	/**
	 * 表名称
	 */
	public static final String table_name = "sb_product_return";

	/**
	 * 字段描述：主键 字段类型：character varying 长度：32
	 */
	public static final String column_ids = "ids";
	/**
	 * 字段描述：机构ids 字段类型：character varying 长度：32
	 */
	public static final String column_organIds = "organIds";
	/**
	 * 字段描述：产品类别 字段类型：character varying 长度：32
	 */
	public static final String column_proType = "proType";
	/**
	 * 字段描述：退款用户字段类型：character varying 长度：32
	 */
	public static final String column_customerIds = "customerIds";
	/**
	 * 字段描述：产品ids字段类型：character varying 长度：32
	 */
	public static final String column_productIds = "productIds";
	/**
	 * 字段描述：产品单价 字段类型：float
	 */
	public static final String column_price = "price";
	/**
	 * 字段描述：退货数量 字段类型：int  
	 */
	public static final String column_num = "num";
	/**
	 * 字段描述：应退金额 字段类型：float
	 */
	public static final String column_amountDue = "amountDue";
	/**
	 * 字段描述：实退金额 字段类型：float
	 */
	public static final String column_actualAmount = "actualAmount";
	
	/**
	 * 字段描述：差异 字段类型：float
	 */
	public static final String column_difference = "difference";
	/**
	 * 字段描述：差异原因 字段类型：character varying 长度：255
	 */
	public static final String column_differenceResion = "differenceResion";
	/**
	 * 字段描述：退款原因 字段类型：character varying 长度：32
	 */
	public static final String column_result = "result";
	/**
	 * 字段描述：退款时间（操作时间） 字段类型：character varying 长度：32
	 */
	public static final String column_time = "time";
	/**
	 * 字段描述：负责人ids 字段类型：character varying 长度：32
	 */
	public static final String column_userIds = "userIds";
	/**
	 * 字段描述：操作者ids 字段类型：character varying 长度：32
	 */
	public static final String column_operatorIds = "operatorIds";
	/**
	 * 字段描述：备注（其他退款原因） 字段类型：character varying 长度：32
	 */
	public static final String column_bz = "bz";
	
	
	
	
	
	/**
	 * 关联查询，获取顾客可退产品信息
	 * 
	 * @return
	 */
	public List<CustomerProduct> getCustomerProducts(String customerIds,String organIds) {
		
		String  sql="SELECT sp.ids  proids, sp.`name`  proname, sp.typeIds  typeids, sys_getCodeName(sp.typeIds) typename, floor(scp.totalExperience/scp.proExperience)  number, price.outPrice  price,"
				+"  floor(scp.totalExperience / scp.proExperience) *  price.outPrice   as total  ,  floor(scp.totalExperience / scp.proExperience) *  price.outPrice  as refund,0  difference"
				+"  FROM  sb_customer_product scp  LEFT JOIN sb_product sp  on scp.productID = sp.ids "
				+"  LEFT JOIN ( SELECT spp.productIds, spp.outPrice, so.ids  orgIds FROM sb_product_price spp "
				+"  LEFT JOIN sys_organization so ON spp.priceIds = so.priceIds where  spp.`status`='1' )  price  on price.productIds=sp.ids and  price.orgIds=scp.organids "  
				+"  where   sp.`status`='1'  and  scp.customerID = ?  and scp.status='1'  AND  scp.organids = ? AND sp.typeIds !='455018290a8f4afbbaf29c61904d6406'";
		
		return CustomerProduct.dao.find(sql,customerIds,organIds);
	}
	
}
